<?php
REQUIRE_ONCE('constants.php');

ob_start();
session_start();

require_once('DB.class.php');
require_once('Node.class.php');
require_once('Nodes.class.php');
require_once('Systype.class.php');

$db = new DB();

function display($options) {
    $content = ob_get_contents();
    ob_end_clean();
    include('templates/master_header.php');
    if (!isset($options['header']) || $options['header']) {
        include('templates/header.php');
    }
    echo $content;
    include('templates/footer.php');
}

function redirect($url) {
    header( 'Location: '.$url );
    exit;
}

function escape($text) {
    return $text;
}

function htmlescape($text) {
    $search =  array('&','"','<','>','\'');
    $replace = array('&amp;','&quot;','&lt;','&gt;','&apos;');
    $text = escape($text);
    return str_replace($search,$replace,$text);
}

function urlescape($text) {
    return str_replace(' ','_',escape($text));
}

function urldeescape($text) {
    return str_replace('_',' ',escape($text));
}

function geturl($name,$id = false) {
    if ($id) { $add = '/node/'.cleanid($id); }
    return DOMAIN.'/'.urlescape($name).$add;
}

function cleanid($id) {
    return (int)$id;
}